﻿Public Class XRAYITEMLIST
    Dim connect As CONDB = CONDB.NewConnection()
    Dim selectsequen As Boolean = False
    Dim s2 As FILTERCLASS
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub COSTTxt_KeyPress(sender As Object, e As KeyPressEventArgs) Handles COSTTxt.KeyPress
        If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And e.KeyChar <> "." Then
            e.Handled = True
        End If
    End Sub

    Private Sub OPDPRCTxt_KeyPress(sender As Object, e As KeyPressEventArgs) Handles OPDPRCTxt.KeyPress
        If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And e.KeyChar <> "." Then
            e.Handled = True
        End If
    End Sub

    Private Sub IPDPRCTxt_KeyPress(sender As Object, e As KeyPressEventArgs) Handles IPDPRCTxt.KeyPress
        If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And e.KeyChar <> "." Then
            e.Handled = True
        End If
    End Sub

    Private Sub CCODETxt_TextChanged(sender As Object, e As EventArgs) Handles CCODETxt.TextChanged
        selectRCODE()
    End Sub

    Private Sub XRAYITEMLIST_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim objSelectDataXrayitem As New XRAYITEM
        SelectDatagridXrayitem()

        'sub หนูน้อยอะไรหว่า
        selectCXRYID()
        'selectSXRYID()
        selectPXRYID()
        selectCCODE()
        selectRCODE()

        Dim sql As String = "SELECT CAST(sxryid as CHAR(8)) AS SXRYID, sxryname FROM maspartxray WHERE `status` = '1'"
        s2 = New FILTERCLASS(SXRYIDTxt, sql, "รหัสส่วน,ส่วน", "50,160", "1,1", "1,1")
        s2.SetShowInDown = False
        s2.SetShowBorder = True
        
        STTDATE.Format = DateTimePickerFormat.Custom
        STTDATE.CustomFormat = " "
        EXPDATE.Format = DateTimePickerFormat.Custom
        EXPDATE.CustomFormat = " "

        DesignForm(Me)
        DesignGrid(XRAYITEMGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridXrayitem()
        Dim objSelectDataxrayitem As New XRAYITEM
        Dim xrayitemData As DataTable
        xrayitemData = connect.GetTable(objSelectDataxrayitem.selectxrayitem_)
        XRAYITEMGrid.PrimaryGrid.DataSource = xrayitemData
        connect.Dispose()
    End Sub

    Private Sub cleardataxray()
        XRYIDTxt.Text = ""
        CXRYIDTxt.Clear()
        CXRYIDTxt.Tag = ""
        SXRYIDTxt.Clear()
        SXRYIDTxt.Tag = ""
        PXRYIDTxt.Clear()
        CODEXRAYTxt.Clear()
        ICD10Txt.Text = ""
        ICD9Txt.Text = ""
        FCODETxt.Text = ""
        XRYENAMETxt.Text = ""
        XRYTNAMETxt.Text = ""
        REMARKTxt.Text = ""
        Dim sqldate As String
        Dim dt As New DataTable
        sqldate = " SELECT CURDATE() "
        dt = connect.GetTable(sqldate)
        STTDATE.Value = Convert.ToDateTime(dt.Rows(0)(0))
        EXPDATE.Value = Convert.ToDateTime(dt.Rows(0)(0))
        PRDCODETxt.Text = ""
        REMARKTxt.Text = ""
        COSTTxt.Text = ""
        XrayitemStatusChk.Checked = False
        CCODETxt.Clear()
        RCODETxt.Clear()
        OPDPRCTxt.Text = ""
        IPDPRCTxt.Text = ""
        PRDCODETxt.Text = ""
    End Sub

    Public Sub selectCXRYID()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(cxryid as CHAR(8)) AS CXRYID, cxryname FROM masclsxray WHERE `status` = '1'"
        s = New FILTERCLASS(CXRYIDTxt, sql, "รหัสประเภท,ชื่อประเภท", "50,160", "1,1", "1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Public Sub selectSXRYID()
        Dim sql As String = "SELECT CAST(sxryid as CHAR(8)) AS SXRYID, sxryname FROM maspartxray WHERE `status` = '1'"
        s2.SetSql = sql
    End Sub

    Public Sub selectSXRYIDByCls()
        Dim sql As String = "SELECT CAST(sxryid as CHAR(8)) AS SXRYID, sxryname FROM maspartxray WHERE `status` = '1' AND cxryid = '" & CXRYIDTxt.Tag & "'"
        s2.SetSql = sql
    End Sub

    Public Sub selectPXRYID()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(pxryid as CHAR(8)) as PXRYID, `pxryname` FROM masposxray WHERE `status` = 1 "
        s = New FILTERCLASS(PXRYIDTxt, sql, "รหัสกลุ่ม,กลุ่ม", "50,160", "1,1", "1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Public Sub selectCCODE()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(ccode as CHAR(8)) as CCODE, name FROM finchcode WHERE `status` = '1'"
        s = New FILTERCLASS(CCODETxt, sql, "รหัสรายได้,รายได้", "50,160", "1,1", "1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Public Sub selectRCODE()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(rcode as CHAR(8)) as rcode, name FROM finrecode WHERE `status` = '1' AND ccode = '" & CCODETxt.Tag & "'"
        s = New FILTERCLASS(RCODETxt, sql, "รหัสรายรับ,รายรับ", "50,160", "1,1", "1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Private Sub CXRYIDTxt_TextChanged(sender As Object, e As EventArgs) Handles CXRYIDTxt.TextChanged
        If Convert.ToString(CXRYIDTxt.Tag) <> "" Then
            selectSXRYIDByCls()
        Else
            selectSXRYID()
        End If

        makeCodeXrayItem()
    End Sub

    Private Sub SXRYIDTxt_TextChanged(sender As Object, e As EventArgs) Handles SXRYIDTxt.TextChanged
        makeCodeXrayItem()
    End Sub

    Private Sub makeCodeXrayItem()
        Dim codeCls As String = ""
        Dim codePart As String = ""
        Dim queryFraction As String = ""
        Dim newXrayItemNum As String = ""

        If CXRYIDTxt.Tag IsNot Nothing And Convert.ToString(CXRYIDTxt.Tag) <> "" Then
            Dim clsDt As DataTable
            clsDt = connect.GetTable("SELECT code FROM masclsxray WHERE cxryid = '" & CXRYIDTxt.Tag & "'")

            If clsDt.Rows.Count > 0 Then
                codeCls = clsDt.Rows(0)(0)
            End If
        End If

        If SXRYIDTxt.Tag IsNot Nothing And Convert.ToString(SXRYIDTxt.Tag) <> "" Then
            Dim partDt As DataTable
            partDt = connect.GetTable("SELECT code FROM maspartxray WHERE sxryid = '" & SXRYIDTxt.Tag & "'")

            If partDt.Rows.Count > 0 Then
                codePart = partDt.Rows(0)(0)
            End If
        End If

        queryFraction = codeCls & "-" & codePart & "-" & "%"

        Dim numXrayDt As DataTable
        Dim numxraySQL As String = "SELECT MAX(`code`) FROM (SELECT `code` FROM xrayitem WHERE `code` LIKE '" & queryFraction & "' ORDER BY `code` DESC) subxray"
        numXrayDt = connect.GetTable(numxraySQL)
        If numXrayDt.Rows.Count > 0 Then
            If numXrayDt.Rows(0)(0) IsNot DBNull.Value Then
                Dim fullCode As String = numXrayDt.Rows(0)(0)
                Dim arrCode As Array
                arrCode = fullCode.Split("-")
                newXrayItemNum = Convert.ToInt64(arrCode(2) + 1)
            Else
                newXrayItemNum = "0001"
            End If
        Else
            newXrayItemNum = "0001"
        End If

        Dim newOfNewXrayItemNum As String = ""
        If newXrayItemNum.Length.ToString = 1 Then
            newOfNewXrayItemNum = "000" & newXrayItemNum
        ElseIf newXrayItemNum.Length.ToString = 2 Then
            newOfNewXrayItemNum = "00" & newXrayItemNum
        ElseIf newXrayItemNum.Length.ToString = 3 Then
            newOfNewXrayItemNum = "0" & newXrayItemNum
        ElseIf newXrayItemNum.Length.ToString = 4 Then
            newOfNewXrayItemNum = newXrayItemNum
        End If

        CODEXRAYTxt.Text = codeCls & "-" & codePart & "-" & newOfNewXrayItemNum
    End Sub

    Private Sub XRAYITEMGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles XRAYITEMGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID").Value() IsNot DBNull.Value Then
            XRYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID").Value()
        Else
            XRYIDTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CODE").Value() IsNot DBNull.Value Then
            CODEXRAYTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CODE").Value()
        Else
            CODEXRAYTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสสินค้า").Value() IsNot DBNull.Value Then
            PRDCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสสินค้า").Value()
        Else
            PRDCODETxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CXRYID").Value() IsNot DBNull.Value Then
            CXRYIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CXRYID").Value()
            CXRYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ประเภท").Value()
        Else
            CXRYIDTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("SXRYID").Value() IsNot DBNull.Value Then
            SXRYIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("SXRYID").Value()
            SXRYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ส่วน").Value()
        Else
            SXRYIDTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("PXRYID").Value() IsNot DBNull.Value Then
            PXRYIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("PXRYID").Value()
            PXRYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("กลุ่ม").Value()
        Else
            PXRYIDTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหัตถการ ICD10-TM").Value() IsNot DBNull.Value Then
            ICD10Txt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหัตถการ ICD10-TM").Value()
        Else
            ICD10Txt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหัตถการ ICD9-CM").Value() IsNot DBNull.Value Then
            ICD9Txt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหัตถการ ICD9-CM").Value()
        Else
            ICD9Txt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสบัญชีกลาง").Value() IsNot DBNull.Value Then
            FCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสบัญชีกลาง").Value()
        Else
            FCODETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหัตถการภาษาอังกฤษ").Value() IsNot DBNull.Value Then
            XRYENAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหัตถการภาษาอังกฤษ").Value()
        Else
            XRYENAMETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหัตถการภาษาไทย").Value() IsNot DBNull.Value Then
            XRYTNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหัตถการภาษาไทย").Value()
        Else
            XRYTNAMETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หมายเหตุ").Value() IsNot DBNull.Value Then
            REMARKTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หมายเหตุ").Value()
        Else
            REMARKTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่เริ่มใช้").Value() IsNot DBNull.Value Then
            STTDATE.Value = Convert.ToDateTime(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่เริ่มใช้").Value())
            STTDATE.Format = DateTimePickerFormat.Custom
            STTDATE.CustomFormat = "dd/MM/yyyy"
        Else
            STTDATE.Format = DateTimePickerFormat.Custom
            STTDATE.CustomFormat = " "
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่เลิกใช้").Value() IsNot DBNull.Value Then
            EXPDATE.Value = Convert.ToDateTime(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วันที่เลิกใช้").Value())
            EXPDATE.Format = DateTimePickerFormat.Custom
            EXPDATE.CustomFormat = "dd/MM/yyyy"
        Else
            EXPDATE.Format = DateTimePickerFormat.Custom
            EXPDATE.CustomFormat = " "
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ต้นทุน").Value() IsNot DBNull.Value Then
            COSTTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ต้นทุน").Value()
        Else
            COSTTxt.Text = ""
        End If
        'If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ต้นทุน").Value() IsNot DBNull.Value Then
        '    COSTTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ต้นทุน").Value()
        'Else
        '    COSTTxt.Text = ""
        'End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สินค้า").Value() IsNot DBNull.Value Then
            XRYENAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สินค้า").Value()
        Else
            XRYENAMETxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CCODE").Value() IsNot DBNull.Value Then
            CCODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CCODE").Value()
            CCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อCCODE").Value()
        Else
            CCODETxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("RCODE").Value() IsNot DBNull.Value Then
            RCODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("RCODE").Value()
            RCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อRCODE").Value()
        Else
            RCODETxt.Clear()
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ราคาขาย OPD").Value() IsNot DBNull.Value Then
            OPDPRCTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ราคาขาย OPD").Value()
        Else
            OPDPRCTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ราคาขาย IPD").Value() IsNot DBNull.Value Then
            IPDPRCTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ราคาขาย IPD").Value()
        Else
            IPDPRCTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            XrayitemStatusChk.Checked = True
        Else
            XrayitemStatusChk.Checked = False
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ตัดสต๊อค").Value() = True Then
            XrayitemStatusStockchk.Checked = True
        Else
            XrayitemStatusStockchk.Checked = False
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CHKIN").Value() = True Then
            XrayitemCheckinChk.Checked = True
        Else
            XrayitemCheckinChk.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE xrayitem SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `xryid` = '" & XRYIDTxt.Text & "' ;"

                Sql += "UPDATE masproduct SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `prdcode` = '" & PRDCODETxt.Text & "' ;"
                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addXrayitem.Enabled = False
        'SelectDatagridXrayitem()
    End Sub

    Private Sub addXrayitem_Click(sender As Object, e As EventArgs) Handles addXrayitem.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If CXRYIDTxt.Text.ToString.Length > 0 And SXRYIDTxt.Text.ToString.Length > 0 And PXRYIDTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New XRAYITEM
                    objInsertData.CODE_ = CODEXRAYTxt.Text
                    objInsertData.CXRYID_ = CXRYIDTxt.Tag
                    objInsertData.SXRYID_ = SXRYIDTxt.Tag
                    objInsertData.PXRYID_ = PXRYIDTxt.Tag
                    objInsertData.ICD10TM_ = ICD10Txt.Text
                    objInsertData.ICD9CM_ = ICD9Txt.Text
                    objInsertData.FCODE_ = FCODETxt.Text
                    objInsertData.XRYENAME_ = XRYENAMETxt.Text
                    objInsertData.XRYTNAME_ = XRYTNAMETxt.Text
                    objInsertData.REMARK_ = REMARKTxt.Text
                    objInsertData.STTDATE_ = DateAdd(DateInterval.Year, -543, STTDATE.Value).ToString("yyyy/MM/dd")
                    objInsertData.EXPDATE_ = DateAdd(DateInterval.Year, -543, EXPDATE.Value).ToString("yyyy/MM/dd")
                    objInsertData.COST_ = COSTTxt.Text
                    objInsertData.CHKIN_ = XrayitemCheckinChk.Checked
                    objInsertData.STATUS_ = XrayitemStatusChk.Checked
                    objInsertData.F_STK_ = XrayitemStatusStockchk.Checked
                    objInsertData.GENERICNAME_ = XRYENAMETxt.Text
                    objInsertData.CCODE_ = CCODETxt.Tag
                    objInsertData.RCODE_ = RCODETxt.Tag
                    objInsertData.OPDPRC_ = OPDPRCTxt.Text
                    objInsertData.IPDPRC_ = IPDPRCTxt.Text
                    objInsertData.insertXrayitem()

                    SelectDatagridXrayitem()

                    cleardataxray()
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editXrayitem_Click(sender As Object, e As EventArgs) Handles editXrayitem.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If XRYIDTxt.Text.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลส่วนดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)
                    If editStat = 1 Then
                        Dim objeditData As New XRAYITEM
                        objeditData.XRYID_ = XRYIDTxt.Text
                        objeditData.CODE_ = CODEXRAYTxt.Text
                        objeditData.CXRYID_ = CXRYIDTxt.Tag
                        objeditData.SXRYID_ = SXRYIDTxt.Tag
                        objeditData.PXRYID_ = PXRYIDTxt.Tag
                        objeditData.ICD10TM_ = ICD10Txt.Text
                        objeditData.ICD9CM_ = ICD9Txt.Text
                        objeditData.FCODE_ = FCODETxt.Text
                        objeditData.XRYENAME_ = XRYENAMETxt.Text
                        objeditData.XRYTNAME_ = XRYTNAMETxt.Text
                        objeditData.REMARK_ = REMARKTxt.Text
                        If STTDATE.CustomFormat <> " " Then
                            objeditData.STTDATE_ = DateAdd(DateInterval.Year, -543, STTDATE.Value).ToString("yyyy/MM/dd")
                        End If
                        If EXPDATE.CustomFormat <> " " Then
                            objeditData.EXPDATE_ = DateAdd(DateInterval.Year, -543, EXPDATE.Value).ToString("yyyy/MM/dd")
                        End If
                        objeditData.COST_ = COSTTxt.Text
                        objeditData.STATUS_ = XrayitemStatusChk.Checked
                        objeditData.CHKIN_ = XrayitemCheckinChk.Checked
                        objeditData.F_STK_ = XrayitemStatusStockchk.Checked
                        objeditData.GENERICNAME_ = XRYENAMETxt.Text
                        objeditData.CCODE_ = CCODETxt.Tag
                        objeditData.RCODE_ = RCODETxt.Tag
                        objeditData.PRDCODE_ = PRDCODETxt.Text
                        objeditData.OPDPRC_ = OPDPRCTxt.Text
                        objeditData.IPDPRC_ = IPDPRCTxt.Text
                        objeditData.editXrayitem()

                        SelectDatagridXrayitem()

                        cleardataxray()
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
                addXrayitem.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("xrayitem")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("xrayitem")
        nextform.ShowDialog()
    End Sub

    Private Sub CXRYIDTxt_Click(sender As Object, e As EventArgs) Handles CXRYIDTxt.Click
        CXRYIDTxt.Clear()
    End Sub

    Private Sub SXRYIDTxt_Click(sender As Object, e As EventArgs) Handles SXRYIDTxt.Click
        SXRYIDTxt.Clear()
    End Sub

    Private Sub PXRYIDTxt_Click(sender As Object, e As EventArgs) Handles PXRYIDTxt.Click
        PXRYIDTxt.Clear()
    End Sub

    Private Sub CCODETxt_Click(sender As Object, e As EventArgs) Handles CCODETxt.Click
        CCODETxt.Clear()
    End Sub

    Private Sub RCODETxt_Click(sender As Object, e As EventArgs) Handles RCODETxt.Click
        RCODETxt.Clear()
    End Sub

    
    Private Sub btnClearForm_Click(sender As Object, e As EventArgs) Handles btnClearForm.Click
        SelectDatagridXrayitem()

        cleardataxray()
    End Sub
End Class